﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using log4net.Config;
using log4net.Appender;
using log4net;
using AuctionHouseDataLibrary;
using System.Threading;

namespace AHDataCollector
{
    public partial class CollectorService : ServiceBase
    {
        public CollectorService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            BasicConfigurator.Configure(new FileAppender(new log4net.Layout.SimpleLayout(), AuctionHouseDataLibrary.Globals.Logfile));
            Globals.Logger = LogManager.GetLogger("");
            AuctionHouseDataLibrary.Globals.Logger = LogManager.GetLogger("");
            // Start up worker threads
            Globals.BackgroundDownloadThread = new BackgroundDownloadThread();
            Globals.RecurringAHScanThread = new RecurringAHScanThread(Globals.BackgroundDownloadThread);
            Thread backgroundWorker = new Thread(Globals.BackgroundDownloadThread.Run);
            Thread recurringWorker = new Thread(Globals.RecurringAHScanThread.Run);
            backgroundWorker.Start();
            recurringWorker.Start();
            Globals.Logger.Info("Application Start");
        }

        protected override void OnStop()
        {
            Globals.BackgroundDownloadThread.Stop();
            Globals.RecurringAHScanThread.Stop();
            Globals.Logger.Info("Application End");
        }
    }
}
